package com.uml.umlwork.controller;

import com.uml.umlwork.config.annotation.UserLoginToken;
import com.uml.umlwork.dto.course.AddCourseDTO;
import com.uml.umlwork.dto.course.UpdateCourseDTO;
import com.uml.umlwork.service.CourseService;
import com.uml.umlwork.utils.SystemMsgJsonResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Siki
 * @date 2021/1/6
 */

@Api(tags = "课程相关模块 - api")
@RequestMapping("/api/v1/umlwork/course")
@RestController
@UserLoginToken
public class CourseController {

    private final CourseService courseService;

    public CourseController(CourseService courseService){
        this.courseService = courseService;
    }

    @PostMapping("/closeCourseByCourseId")
    @ApiOperation(value = "[课程]-关闭选课",httpMethod = "POST")
    public SystemMsgJsonResponse closeCourseByCourseId(@RequestParam("courseId") Integer courseId,
                                                       @RequestParam("open") Integer open) {
        courseService.closeCourseByCourseId(courseId,open);
        return SystemMsgJsonResponse.success();
    }

    @PostMapping("/createCourse")
    @ApiOperation(value = "[课程]-开设课程",httpMethod = "POST")
    public SystemMsgJsonResponse createNewCourse(@RequestBody @Validated AddCourseDTO dto) {
        courseService.createNewCourse(dto);
        return SystemMsgJsonResponse.success();
    }

    @GetMapping("/deleteCourse")
    @ApiOperation(value = "[课程]-删除课程",httpMethod = "GET")
    public SystemMsgJsonResponse deleteCourse(@RequestParam("courseId") Integer courseId) {
        courseService.deleteCourse(courseId);
        return SystemMsgJsonResponse.success();
    }

    @PostMapping("/updateCourse")
    @ApiOperation(value = "[课程]-修改课程",httpMethod = "POST")
    public SystemMsgJsonResponse updateCourse(@RequestBody @Validated UpdateCourseDTO dto) {
        courseService.updateCourse(dto);
        return SystemMsgJsonResponse.success();
    }
}
